
import { commonConstants } from 'hhlt-core/constants'
import { systemUtils} from 'hhlt-core/utils'
import { formatUtils,requestUtils} from 'hhlt-vue/utils'
import { IPageInfo} from 'hhlt-core/src/model/page/pageInfo'
import { IDataTablePager} from 'hhlt-core/src/model/page/dataTablePager'
import { VxeGridPropTypes, VxeTableDefines } from 'vxe-table'
import { IColumnInfo} from 'hhlt-core/src/model/form/column'
import { IExecuteData} from 'hhlt-core/src/model/base/resultModel'
import { FormRules } from 'element-plus'
import { fixedDatasource} from "hhlt-core/constants"
import { objectUtils } from 'hhlt-core/utils'
import { requestContextPath } from 'lxsh-cer-web-pc/src/constants'
import { ICerSupplierImpro, ICerSupplierImproQO, ICerSupplierImproVO,CerSupplierImpro } from 'lxsh-cer-web-pc/src/model/cer/cer/supplier-impro/cer-supplier-impro'
/**
* 供应商减碳业务实现
*/
export default {
//获取页面信息，根据不同的功能编码来加载不同的页面
getPageInfo:function(pageInfo:IPageInfo<ICerSupplierImpro>){
  this.getColumnInfo()
},
/**
* 获取列信息
*/
getColumnInfo(successCallback?:(columnsParam:VxeGridPropTypes.Columns)=>void){
    var columns:VxeGridPropTypes.Columns = [
      { type: 'checkbox', width: 50 },
      { type: 'seq', width: 60,align:'center',title:'序号' },
      { field: 'id', title: '主键ID', visible:false },
      { field: 'transDate', title: '日期', formatter: formatUtils.formatDateDefault, showOverflow: true, sortable: true ,width:'160px'},
      { field: 'supplierName', title: '供应商名称', showOverflow: true, sortable: true,width:'115px' },
      { field: 'supplierType', title: '供应原材料类型', showOverflow: true, sortable: true,width:'145px' },
      { field: 'supplierCount', title: '供应原材料数量', showOverflow: true, sortable: true,width:'145px' },
      { field: 'reduceCount', title: '本批次比上批次生产减少碳排放量', showOverflow: true, sortable: true,width:'265px' },
      { field: 'carbonCount', title: '本批次原料运输碳排放减少量', showOverflow: true, sortable: true,width:'235px' },
      { field: 'addDate', title: '添加时间', formatter: formatUtils.formatDateDefault, showOverflow: true, sortable: true ,width:'160px'},
      { title: '操作', width: 200, slots: { default: 'operate' },fixed:'right' }
    ];
    if(successCallback){
      successCallback(columns);
    }
  },
  /**
   * 获取检索条件
   */
  getSearchCondition(successCallback:(searchCondtionParam:IColumnInfo[],queryParams:ICerSupplierImproQO) => void){
    var searchCondition = [
      { columnCode: 'transDate', columnName: '日期', basicControlType:commonConstants.enumBasicControlType.DATE,defaultValue:"",controlAttrValue:"" },
      { columnCode: 'supplierName', columnName: '供应商名称', basicControlType:commonConstants.enumBasicControlType.TEXT_BOX,defaultValue:"",controlAttrValue:"" },
      { columnCode: 'supplierType', columnName: '供应原材料类型', basicControlType:commonConstants.enumBasicControlType.TEXT_BOX,defaultValue:"",controlAttrValue:"" },
    ];
    var queryParam:ICerSupplierImproQO = {
        id:undefined,
       /**
	    * transDate:日期
	    */
    transDate: undefined,
       /**
	    * supplierName:供应商名称
	    */
    supplierName:"",
       /**
	    * supplierType:供应原材料类型
	    */
    supplierType:"",
    }
    return successCallback(searchCondition,queryParam);
  },
  /**
   * 单条删除操作
   */
  doDeleteSingle(selectItem:ICerSupplierImproVO,successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/supplierImpro/deleteByLogicBatch';
    let list = new Array();
    let item:ICerSupplierImproQO = {
      id:selectItem.id
    }
    list.push(item)
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 单条删除操作
   */
  doDeleteBatch(selectList:ICerSupplierImproVO[],successCallback?:(deleteResult:IExecuteData<string>)=>void):Promise<IExecuteData<string>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/supplierImpro/deleteByLogicBatch';
    let list = new Array();
    for (let selectItem of selectList) {
      let item :ICerSupplierImproVO = {
        id:selectItem.id
      };
      list.push(item);
    }
    return requestUtils.delete(url, list,successCallback);
  },
  /**
   * 获取分页数据
   */
  getListByPager(queryParam:ICerSupplierImproQO,pager:IDataTablePager<ICerSupplierImproVO>,successCallback?:(queryResult:IExecuteData<IDataTablePager<ICerSupplierImproVO>>) => void):Promise<IExecuteData<IDataTablePager<ICerSupplierImproVO>>>{
    let url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + '/cer/supplierImpro/getListByPager';
    return  requestUtils.getListByPager(url, queryParam, pager,successCallback)
  },
  addForm(formData:ICerSupplierImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/supplierImpro/insert";
    return requestUtils.insert(url, formData,successCallback);
  },
  updateForm(formData:ICerSupplierImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/supplierImpro/update";
    return requestUtils.update(url, formData,successCallback);
  },
  updateEnable(formData:ICerSupplierImpro,successCallback?:(result:IExecuteData<string>) => void):Promise<IExecuteData<string>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/supplierImpro/updateEnable";
    return requestUtils.update(url, formData,successCallback);
  },
  getInfoByCondition(param:ICerSupplierImproQO,successCallback?:(result:IExecuteData<ICerSupplierImproVO>) => void):Promise<IExecuteData<ICerSupplierImproVO>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/supplierImpro/getInfoByCondition";
    return requestUtils.getInfoByCondition(url, param,successCallback);
  },
  exportExcel(param:any,fileName:string,successCallback?:(result:IExecuteData<String>) => void):Promise<IExecuteData<String>>{
    var url = systemUtils.getContextPath<typeof requestContextPath>(requestContextPath,"cer") + "/cer/supplierImpro/exportExcel";
    const result:any = requestUtils.exportExcel(url, param,fileName,successCallback);
    if(result.success){
      if(successCallback){
        successCallback(result)
      }
    }
    return result;
  },
  //获取表单项
  getFormDataItem(successCallback:(formData:ICerSupplierImpro,verify:FormRules) => void){
    var formData:ICerSupplierImpro = new CerSupplierImpro()
        // 校验
    var verify:FormRules = {
        transDate: [{
            required: true,
            message: "日期不能为空！"
        }],
        supplierName: [{
            required: true,
            message: "供应商名称不能为空！"
        }],
        supplierType: [{
            required: true,
            message: "供应原材料类型不能为空！"
        }],
        supplierCount: [{
            required: true,
            message: "供应原材料数量不能为空！"
        }],
        reduceCount: [{
            required: true,
            message: "本批次比上批次生产减少碳排放量不能为空！"
        }],
        carbonCount: [{
            required: true,
            message: "本批次原料运输碳排放减少量不能为空！"
        }],
    }
    return successCallback(formData,verify)
  }
}
